|
|
|
|
|
|
|
Sometimes your program may need to display more information than can fit on a single form. In that case, you might like to display the information in a scrolled window. Unfortunately Visual Basic does not have a scrolled window control, so this is not easy, but you can use Visual Basic's controls to build a scrolling window yourself. |
|
|
|
|
|
|
|
|
Place a PictureBox named picOuter on a form. Inside picOuter, place another PictureBox named picInner. Make sure picInner is contained inside picOuter and not just sitting on top of it. Next, place horizontal and vertical scroll bars next to picOuter. |
|
|
|
|
|
|
|
|
Now put whatever information you want to scroll inside picInner. For example, to display a large image, set picInner's Picture property to the image. Set picInner's AutoSize property to True so that the control resizes to fit the image. |
|
|
|
|
|
|
|
|
Because it is contained in picOuter, picInner is clipped if it extends beyond the edges of picOuter. When the user changes the scroll bar values, the program should adjust picInner's Left and Top properties. That makes different parts of picInner visible inside picOuter, so the image appears to scroll. |
|
|
|
|
|
|
|
|
Example program Scroll, shown in Figure 1.14, displays a large image in a scrolled window. |
|
|
|
|
|
|
|
|
Example program Scroll manages its scrolled window with the following code. The most interesting part of the program is the ArrangeControls subroutine. ArrangeControls determines how big picInner is and how much space is available on the form, subtracting room for picOuter's borders. It compares the space required with the space available to see which scroll bars it needs. Notice that any scroll bar it uses reduces the space available. That means using one scroll bar may require the use of the other. |
|
|
|
 |
|
|
|
|
Option Explicit
Private Sub Form_Load()
picInner.AutoSize = True
picInner.Move 0, 0
End Sub |
|
|
|
|
|
|
|
|
Figure 1.14
Example program Scroll displays a large
image in a scrolled window. |
|
|
|
|
|